<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="审批类型" prop="name">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择"
          class="w100"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_examine_flow"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审批状态" prop="name">
        <el-select v-model="queryParams.style" placeholder="审批状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_approve_examine_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          plain
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="postList"
    >
      <el-table-column label="申请人" align="center" prop="name">
        <template slot-scope="scope">
          {{ scope.row.sysUser ? scope.row.sysUser.nickName : '' }}
        </template>
      </el-table-column>
      <el-table-column label="审批类型" align="center" prop="name">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_examine_flow"
            :value="scope.row.type"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        align="center"
        prop="num"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_approve_examine_status"
            :value="scope.row.examineUser.isExamine"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="申请时间"
        prop="createTime"
        align="center"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['system:examine:list']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <component :is="componentName" type="examine" :paramId="paramId" :visible.sync="showDetail"
               @getExamineFn="getExamineFn" :noticeId="examineId.id || 0" :isExamine="isExamine"></component>
  </div>
</template>

<script>
import {
  listExamine, getExamine, examineFlow
} from "@/api/system/examine";
import leave_detail from "@/views/approval/examine/leave/detail"
import overtime_detail from "@/views/approval/examine/overtime/detail"
import card_replacement_detail from "@/views/approval/examine/card_replacement/detail"
import invoice_detail from "@/views/system/dept/components/invoiceExamine"
import {mapGetters} from 'vuex'

export default {
  name: "StagnationPoint",
  dicts: ['sys_stagnation_type', 'sys_examine_flow', 'sys_approve_examine_status'],
  components: {leave_detail, overtime_detail, card_replacement_detail, invoice_detail},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        style: undefined,
        createTime: 'asc' // asc desc
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      paramId: 0,
      teamVisible: false,
      param: null,
      zhudianVisible: false,
      listVisible: false,
      schedulingVisible: false,
      detailVisible: false,
      componentName: '',
      showDetail: false,
      examineId: 0,
      isExamine: false
    };
  },
  computed: {
    ...mapGetters([
      'deptId',
      'userId'
    ]),
  },
  watch: {},
  created() {
    let receiveId = this.$route.params && this.$route.params.receiveId;
    console.log('this.receiveId', receiveId)
    if(receiveId!=='4'){
      this.queryParams.style = receiveId
    }
    this.getList()
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listExamine(this.queryParams).then(response => {
        for (let item of response.rows) {
          if (item.examineUser.isExamine == 1) {
            item.examineStatus = 1
          } else {
            item.examineStatus = 0
          }
        }
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 审核通知 examineFlow
    getExamineFn(option) {
      // id 审核通知id
      // 可选
      // logId 步骤id
      // 可选
      // examineLog
      // ["id ID","examineUser 已经审核用户","isExamine 步骤结束后提交通过还是驳回"]
      // 通过 1 驳回 2
      let that = this
      let data_ = {
        id: this.examineId.id,
        logId: this.examineId.examineLog.id,
        examineUser: {id: this.examineId.examineUser.id, isExamine: option}
      }
      let title = '确认同意该申请, 是否继续?'
      if (option == 2) {
        title = '确认驳回该申请, 是否继续?'
      }
      this.$confirm(title, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        console.log('data_:', data_)
        that.$modal.loading("处理中，请稍候...");
        return examineFlow(data_);
      }).then(() => {
        that.$modal.closeLoading();
        that.getList();
        that.$modal.msgSuccess("操作成功");
      }).catch((res) => {
        console.log('res===>', res)
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.type = undefined
      this.handleQuery();
    },
    handleView(row) {
      // : {leave_detail, overtime_detail, card_replacement_detail},
      //  审批类型 请假 11；补卡 12；加班 13；销价 14；入职 21；转正 22；调薪资 23；调岗 24；离职 25；发票 26
      let that = this
      this.examineId = this.$deepCopy(row)
      this.paramId = row.detailId // 请假具体详情
      this.isExamine = !row.examineUser.isExamine ? true : false
      that.componentName = 'card_replacement_detail'
      // getExamine(row.id).then(res => {
      //   console.log('res==>', res)
      // })
      // let status = 1
      // if (status) {
      //   return
      // }
      switch (row.type) {
        case 11:
          that.componentName = 'leave_detail'
          break;
        case 12:
          that.componentName = 'card_replacement_detail'
          break;
        case 13:
          that.componentName = 'overtime_detail'
          break;
        case 14:
          break;
        case 21:
          break;
        case 22:
          break;
        case 23:
          break;
        case 24:
          break;
        case 25:
          break;
        case 26:
          that.componentName = 'invoice_detail'
          break;
      }
      this.$nextTick(() => {
        that.showDetail = true
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除执勤点为"' + row.name + '"的数据项？').then(function () {
        // return delStagnationPoint(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.points-map {
  height: 400px;
}

.points-map__tip {
  color: #010101;
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
}

.point-radius {
  margin-bottom: 20px;
  padding: 0 20px;

  .point-radius__len {
    margin-top: 10px;
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;
    color: #010101;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
  }
}

.mapBox {
  margin-bottom: 20px;
  padding: 0 20px;
}
</style>
